﻿#pragma once
#include"Define.h"
#include"ObjectList.h"
#include<iostream>

using namespace std;

class Basket{
	float x, y;
	float vx, vy;
	bool bMoveMouse;
public:
	Basket() : x(-WIDTH/2+50), y(-HEIGHT/2+100),vx(0),vy(0){}
	//Hien thi gio hung
	void display()
	{
		glPushMatrix();
		glColor3f(1, 1, 1);
		glTranslatef(x, y, 0);
		glTranslatef(-x, -y, 0);
		DrawTexture(x,y,BASKET,-1,-1);
		glPopMatrix();
		glEnd();
	}

	//Timer 
	void Timer()
	{
		
		if (bMoveMouse==true)//Neu dung chout
		{
			if((Mouse.x <=(WIDTH / 2-50)) &&(Mouse.x >=(-WIDTH /2+50) ))
			x=Mouse.x;
			vx =0;
			fX =x-Textures[BASKET].width/2 +20;
			fY=y+Textures[BASKET].height/2+20;
		}
		if(((x+vx )<=(WIDTH / 2-50)) &&((x+vx ) >=(-WIDTH /2+50) )){
			x += vx;
			Mouse.x=x;
			Mouse.y =y;
			fX =x-Textures[BASKET].width/2 +20;
			fY=y+Textures[BASKET].height/2+20;
			vx=0;
		}
		bMoveMouse=true;
	}
	//Su dung phim trai , phai
	void Keyboard(int key)	{
		const float Speed = 10;
		switch (key){
			case GLUT_KEY_LEFT:{
					vx = -Speed;
					bMoveMouse=false;
				}
				break;
			
			case GLUT_KEY_RIGHT:{
					vx = Speed;
					bMoveMouse=false;
				}
					break;
			default:
				break;
			}
		}
};
